<%@ page language="java" import="java.util.*,shop.dao.*,shop.entity.*" 	pageEncoding="utf-8"%>
<%
String text = new String(request.getParameter("text").getBytes("ISO-8859-1"),"utf-8");
String p_ID =request.getParameter("p_ID");
String grade = new String(request.getParameter("grade").getBytes("ISO-8859-1"),"utf-8");
	String username=(String)session.getAttribute("username");


	if(username=="" || username==null)
	{
		out.print("<script>alert('请先登录!');window.location='../login.jsp'</script>");
		//request.setAttribute("loginError","你还没登录，请登录..");
		//request.getRequestDispatcher("../login.jsp").forward(request,response);
	}
	else{
    Comment comment=new Comment();
	CommentDao commentdao = new CommentDao();
	

	
	if (text == null || text == "" ||grade == null || grade == "") {
	
		out.print("<script>alert('没有填写内容');history.go(-1);</script>");
	} else {
	      //添加评论操作
	    comment.setP_ID(p_ID);
	    comment.setContents(text);
	    comment.setGrade(grade);
	    comment.setWirteName(username);
	    
		int count = commentdao.insertcomment(comment);
		if (count > 0) {
		
		out.println("<script>alert('评论成功!');</script>");
		response.setHeader("refresh","0;url=../showProductMessage.jsp?p_id="+p_ID);
		
		//javax.swing.JOptionPane.showMessageDialog(null,"评论成功");
		//Thread.sleep(500);
		//response.sendRedirect("../showProductMessage.jsp?p_id="+p_ID);
		} else {
			out
			.print("<script>alert('评论失败。');history.go(-1);</script>");
		}
		}
	}
%>
